package jiandian;


/**
 * todo
 *
 * @author: luolidong
 * @create: 2021-07-09 20:12
 * @version: 1.0
 */
public class Demo4 {
    public String addBinary(String a, String b) {
        int i=a.length()-1;
        int j=b.length()-1;
        int a1=0;
        int b1=0;
        int carry=0;
        StringBuilder sb=new StringBuilder();
        while(i>=0||j>=0||carry>0){
            a1=i<0? 0:a.charAt(i)-'0';
            b1=j<0? 0:b.charAt(j)-'0';
            int sum=a1+b1+carry;
            carry=sum/2;
            sb.append(sum%2);
            j--;
            i--;
        }
        return sb.reverse().toString();
    }

    public static void main(String[] args) {
        String s = new Demo4().addBinary("10", "11");
        System.out.println(s);
    }
}

